﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using tactics.GUI.DialogBox;
using tactics.Interfaces;

namespace tactics.Commands
{
    using Coord = Utility.Pair<int, int>;

    class MoveUnitWithPromptCommand : BaseCommand
    {
        okFunction      accept;
        cancelFunction  cancel;

        Coord moveFrom;
        Coord moveTo;
        Unit unit;
        Dictionary<int, int> movePath;

        public MoveUnitWithPromptCommand(Unit unitIn, Coord coord)
        {
            unit = unitIn;
            moveTo = coord;
            moveFrom = new Coord(unit.X, unit.Y);
            movePath = TacticsEngine.Instance.Game.TurnManager.GetUnitMovePath();

            accept = new okFunction(AcceptMove);
            cancel = new cancelFunction(CancelMove);

            Finished = false;

            CommandQueue.Instance.AddCommand(new EnableDisableMouseCommand(false));
        }

        public override void Execute()
        {
            unit.Move(moveTo.First, moveTo.Second, false);
            var dialog = new DialogBox("Move", "Move Here?", "", 250, 120, true, accept, cancel);
        }

        private void AcceptMove()
        {
            CommandQueue.Instance.AddCommand(new MoveUnitCommand(unit, moveTo, movePath));
            CommandQueue.Instance.AddCommand(new EnableDisableMouseCommand(true));

            Finished = true;
        }

        private void CancelMove()
        {
            unit.Move(moveFrom.First, moveFrom.Second, true);
            unit.Moved = false;
            unit.AvailableThisTurn = true;

            CommandQueue.Instance.AddCommand(new EnableDisableMouseCommand(true));

            Finished = true;
        }
    }
}
